﻿@helper FixLinks(string text)
{
    System.Text.RegularExpressions.Regex urlregex = new System.Text.RegularExpressions.Regex(@"(http(s)?:\/\/([\w.]+\/?)\S*)",
        System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Compiled);
    System.Text.RegularExpressions.Regex atregex = new System.Text.RegularExpressions.Regex(@"(^|\s)@(\w+)",
        System.Text.RegularExpressions.RegexOptions.Compiled);
    System.Text.RegularExpressions.Regex hashregex = new System.Text.RegularExpressions.Regex(@"(^|\s)#(\w+)",
        System.Text.RegularExpressions.RegexOptions.Compiled);

    text = urlregex.Replace(text, "<a href=\"$1\" target=\"_blank\">$1</a>");
    text = atregex.Replace(text, "$1@<a href=\"http://www.twitter.com/$2\" target=\"_blank\">$2</a>");
    text = hashregex.Replace(text, "$1#<a href=\"http://search.twitter.com/search?q=%23$2\" target=\"_blank\">$2</a>");
    
    @(new HtmlString(text));
}

